package com.pinda.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pinda.base.entity.PdTransportLine;
import com.pinda.base.entity.PdTransportLineType;
import com.pinda.commonutils.Page;
import com.pinda.commonutils.Result;

import com.pinda.commonutils.StatusCode;
import com.pinda.mapper.PdTransportLineTypeMapper;
import com.pinda.service.IPdTransportLineTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 线路类型表 服务实现类
 * </p>
 *
 * @author lc
 * @since 2023-06-14
 */
@Service
public class PdTransportLineTypeServiceImpl extends ServiceImpl<PdTransportLineTypeMapper, PdTransportLineType> implements IPdTransportLineTypeService {


    @Autowired
    PdTransportLineTypeMapper pdTransportLineTypeMapper;

    @Override
    public Result queryPageTransportLineType(Page<PdTransportLineType> page) {
        System.out.println(page);
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        PdTransportLineType search = page.getSearch();
        QueryWrapper queryWrapper = new QueryWrapper();
        if(search.getId()!=null&& !search.getId().equals("")){
            queryWrapper.like("id",search.getId());
        }
        if(search.getName()!=null){
            queryWrapper.like("name",search.getName());
        }
        if(search.getEndAgencyType()!=null){
            queryWrapper.eq("start_agency_type",search.getEndAgencyType());
            queryWrapper.or();
            queryWrapper.eq("end_agency_type",search.getEndAgencyType());
        }
        PageInfo pageInfo = new PageInfo(this.pdTransportLineTypeMapper.selectList(queryWrapper));
        if(pageInfo!=null){
            return new Result(true, StatusCode.OK,"成功",pageInfo);
        }

        return new Result(true, StatusCode.ERROR,"失败",pageInfo);
    }
}
